package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
@Autowired
private NursingLevelMapper nursingLevelMapper;
@Autowired
NursingPlanService nursingPlanService;
    @Override
    public List<NursingLevelVo> getAllPlan() {
        return nursingLevelMapper.getAllPlan();
    }

    @Override
    public void addNursingLevel(NursingLevelVo nursingLevelVo) {
//       // 重名判断
//        long ii=nursingLevelVo.getId();
//        if(nursingPlanService.getById(ii)!=null){
//            throw new BaseException(BasicEnum.LALBLDUO_AICHIROU);
//        }
        nursingLevelVo.setId(null);
        nursingLevelVo.setCreateTime(null);
        nursingLevelVo.setUpdateTime(null);
        nursingLevelVo.setCreateBy(null);
        nursingLevelVo.setUpdateBy(null);
        nursingLevelMapper.addNursingLevel(nursingLevelVo);
    }

    @Override
    public PageResponse<NursingLevelVo> getByPagePlan(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevelVo> nursingProjects = (Page<NursingLevelVo>) nursingLevelMapper.selectByPagePlan(name, status);
        PageResponse<NursingLevelVo> projectVoPageResponse = PageResponse.of(nursingProjects, NursingLevelVo.class);
        return projectVoPageResponse;
    }

    @Override
    public NursingLevelVo getById(Long id) {
        //异常处理，如果没查到数据抛出异常id不存在
        if (nursingLevelMapper.getById(id) == null) {
            throw new BaseException(BasicEnum.NURSING_PROJECT_SELECT_NULL);
        }
        return nursingLevelMapper.getById(id);
    }

    @Override
    public void updateNursingLevel(NursingLevelVo nursingLevelVo) {
        //异常处理

        nursingLevelMapper.updateNursingLevel(nursingLevelVo);
    }

    @Override
    public void deleteNursingLevelById(Long id) {
        nursingLevelMapper.deleteNursingLevelById(id);
    }

    @Override
    public void sdd(Long id, Integer status) {
        nursingLevelMapper.o(id,status);
    }
}
